<template>
  <j-modal
    :title="title"
    :width="modelStyle.width"
    :visible="visible"
    :bodyStyle="bodyStyle"
    :switchFullscreen="switchFullscreen"
    @cancel="handleCancel"
  >
    <template slot="footer">
      <a-button key="back" @click="handleCancel">关闭</a-button>
      <a-button v-if="record.openType==='url' || record.openType==='start_url'|| record.openType==='salary_url'" type="primary" @click="toHandles">{{message}}</a-button>
    </template>
    <a-card class="daily-article" :loading="loading">
      <a-card-meta
        :title="record.titile"
        :description="'发布人：'+record.sender + ' 发布时间： ' + record.sendTime">
      </a-card-meta>
      <a-divider />
      <span v-html="record.msgContent" class="article-content"></span>
    </a-card>
    <HisNoTaskDealModal ref="taskHisModal" :path="path" :formData="formData" />
    <TaskSignModal ref="tSignModal" :path="path" :formData="formData" />
    <TaskDealModal ref="tDealModal" :path="path" :formData="formData" />
  </j-modal>
</template>

<script>
// import HisNoTaskDealModal from "@/views/modules/bpm/task/HisNoTaskDealModal.vue";
// import TaskSignModal from '@/views/modules/bpm/task/TaskSignModal';
// import TaskDealModal from '@/views/modules/bpm/task/TaskDealModal';
import { isURL } from '@/utils/validate'
import { getAction } from '@/api/manage'

  export default {
    name: 'ShowAnnouncement',
    components: {
      HisNoTaskDealModal: () => import('@/views/modules/bpm/task/HisNoTaskDealModal'),
      TaskDealModal: () => import('@/views/modules/bpm/task/TaskDealModal'),
      TaskSignModal: () => import('@/views/modules/bpm/task/TaskSignModal'),
    },
    data () {
      return {
        message:"去处理",
        title: '通知消息',
        formData:{},
        path:"modules/bpm/task/form/FormLoading",
        record: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 }
        },
        visible: false,
        switchFullscreen: true,
        loading: false,
        bodyStyle: {
          padding: '0',
          height: (window.innerHeight * 0.8) + 'px',
          'overflow-y': 'auto'
        },
        modelStyle: {
          width: '60%',
          style: { top: '20px' },
          fullScreen: false
        },
        url: {
          getProcessNodeInfo: "/api/erpmng/act/process/extActProcessNode/getProcessNodeInfo",
          getHisProcessNodeInfo: "/api/erpmng/act/process/extActProcessNode/getHisProcessNodeInfo",
        },
      }
    },
    created () {
    },
    methods: {
      getProcessMessageInfo(record,type) {
        let params = { taskId: record.id };//查询条件
        getAction(this.url.getProcessNodeInfo, params).then((res) => {
          if (res.success) {
            let data = {
              dataId: res.result.dataId,
              isSubmit: res.result.isSubmit,
              isValForm: res.result.isValForm,
              taskId: record.id,
              taskDefKey: res.result.taskDefKey,
              procInsId: record.processInstanceId,
              tableName: res.result.tableName,
              permissionList: res.result.permissionList,
              vars: res.result.records,
              bizTaskList: res.result.bizTaskList
            }
            this.formData = data;
            console.log(this.formData);
            //update--begin--autor:scott-----date:20191005------for：流程节点配置组件URL的时候也支持传递参数了，解决TASK #3238流程节点无法与online的复制视图对接------
            let tempFormUrl = ''
            if(type === 'sign') {
              tempFormUrl = res.result.formDetailUrl;
            }else {
              tempFormUrl = res.result.formUrl;
            }
          
            //节点配置表单URL，VUE组件类型对应的拓展参数
            if (tempFormUrl && tempFormUrl.indexOf("?") != -1 && !isURL(tempFormUrl) && tempFormUrl.indexOf("{{DOMAIN_URL}}") == -1) {
              let qv = this.getQueryVariable(tempFormUrl)
              this.formData.extendUrlParams = qv
              if (qv.edit == 1) {
                this.formData['disabled'] = false
              }
              tempFormUrl = tempFormUrl.split("?")[0];
              console.log("获取流程节点表单URL（去掉参数）", tempFormUrl);
              //update--begin--autor:taoyan-----date:20200729------for：支持新版代码生成器，简易实现表单带button编辑效果------
              
              //update--end--autor:taoyan-----date:20200729------for：支持新版代码生成器，简易实现表单带button编辑效果------
            }

            //update--begin--autor:scott-----date:20191005------for：节点配置设计器表单的URL，需要参数传递taskid，用于节点表单权限------
            //如果没有taskId参数，程序自动追加，用于设计器表单节点权限
            if (tempFormUrl != null && tempFormUrl.indexOf("{{DOMAIN_URL}}/api/erpmng/desform/") != -1 && tempFormUrl.indexOf("taskId") == -1) {
              tempFormUrl = tempFormUrl.trim();
              if (tempFormUrl.endsWith("?")) {
                tempFormUrl = tempFormUrl + 'taskId=' + record.taskId;
              } else {
                tempFormUrl = tempFormUrl + '&taskId=' + record.taskId;
              }
            }
            this.path = tempFormUrl;
            //update--end--autor:scott-----date:20191005------for：节点配置设计器表单的URL，需要参数taskid，用于节点表单权限-----

            //update--end--autor:scott-----date:20191005------for：流程节点配置组件URL的时候也支持传递参数了，解决TASK #3238流程节点无法与online的复制视图对接------
            if (type === 'sign') {
              this.$refs.tSignModal.isValForm = "1";
              this.$refs.tSignModal.deal(record);
              this.$refs.tSignModal.title = "流程详情";
            } else {
              this.$refs.tDealModal.isValForm = "1";
              this.$refs.tDealModal.deal(record);
              this.$refs.tDealModal.title = "流程办理";
            }

          } else {
            this.getHisProcessNodeInfo(record)
          }
        })
      },
      getHisProcessNodeInfo(record) {
        var params = { procInstId: record.processInstanceId, taskId: record.taskId };//查询条件
        getAction(this.url.getHisProcessNodeInfo, params).then((res) => {
          if (res.success) {
            console.log("获取流程节点信息", res);
            var data = {
              dataId: res.result.dataId,
              taskId: record.id,
              taskDefKey: record.taskId,
              procInsId: record.processInstanceId,
              tableName: res.result.tableName,
              vars: res.result.records
            }
            this.formData = data;
            //update--begin--autor:scott-----date:20191005------for：流程节点配置组件URL的时候也支持传递参数了，解决TASK #3238流程节点无法与online的复制视图对接------

            let tempFormUrl = res.result.formUrl;
            //节点配置表单URL，VUE组件类型对应的拓展参数
            if (tempFormUrl && tempFormUrl.indexOf("?") != -1 && !isURL(tempFormUrl) && tempFormUrl.indexOf("{{DOMAIN_URL}}") == -1) {
              tempFormUrl = res.result.formUrl.split("?")[0];
              this.formData.extendUrlParams = this.getQueryVariable(res.result.formUrl)
            }
            this.path = tempFormUrl;
            //update--end--autor:scott-----date:20191005------for：流程节点配置组件URL的时候也支持传递参数了，解决TASK #3238流程节点无法与online的复制视图对接------
            if (!!record.isComplated) {
              this.formData.isComplated = '1'
            }
            this.$refs.taskHisModal.deal(record);
            this.$refs.taskHisModal.title = "流程历史";
          }
        })
      },
      //获取URL上参数
      getQueryVariable(url) {
        if (!url) return

        var t, n, r, i = url.split("?")[1], s = {};
        t = i && i.split("&"),
          r = null,
          n = null;
        for (var o in t) {
          var u = t[o].indexOf("=");
          u !== -1 && (r = t[o].substr(0, u),
            n = t[o].substr(u + 1),
            s[r] = n)
        }
        return s
      },
      detail (record) {
        this.visible = true;
        this.record = record;
        if (this.record.openType === 'salary_url') {
          this.message = "去查看"
        }else{
          this.message = "去处理"
        }
      },
      handleCancel () {
        this.visible = false;
      },
      /** 切换全屏显示 */
      handleClickToggleFullScreen() {
        let mode = !this.modelStyle.fullScreen
        if (mode) {
          this.modelStyle.width = '100%'
          this.modelStyle.style.top = '20px'
        } else {
          this.modelStyle.width = '60%'
          this.modelStyle.style.top = '50px'
        }
        this.modelStyle.fullScreen = mode
      },
      toHandles() {
        const arrTitle = ['退回','知会','转发']
        const data = {
          processInstanceId: this.record.procInstId,
          taskId: this.record.taskId,
          id: this.record.taskId,
        }
        if(this.record.titile == "流程催办提醒"){
          
          this.getProcessMessageInfo(data)

        } else if (arrTitle.includes(this.record.titile.substring(1,3))){

          this.getHisProcessNodeInfo(data,'sign')

        } else if (this.record.titile.indexOf("通知公告")!=-1) {

          this.visible = false;
          this.$router.push({ path: '/erp/docManage/noticeAnnounceList', query: { key: '3' } })

        } else if (this.record.titile.indexOf("意见征集")!=-1) {

          this.visible = false;
          this.$router.push({ path: '/erp/docManage/opinionCollectList', query: { key: '3' } })

        } else {
          if (this.record.openType === 'url') {
            this.visible = false;
            // 链接跳转
            this.$router.push({ path: this.record.openPage, query: { key: '3' } })
          }
          if (this.record.openType === 'start_url') {
            this.visible = false;
            // 链接跳转
            this.$router.push({ path: this.record.openPage, query: { key: '4' } })
          }
          if (this.record.openType === 'salary_url') {
            this.visible = false;
            // 链接跳转
            this.$router.push({ path: this.record.openPage, query: { key: '8' } })
          }
        }
      }
    }
  }
</script>

<style lang="less">
  .announcementCustomModal{
    .ant-modal-header {
      border: none;
      display: inline-block;
      position: absolute;
      z-index: 1;
      right: 56px;
      padding: 0;
      .ant-modal-title{
        .custom-btn{
          width: 56px;
          height: 56px;
          border: none;
          box-shadow: none;
        }
      }
    }
    .daily-article{
      border-bottom: 0;
    }
  }
</style>
<style scoped lang="less">
  .daily-article {
    .article-button {
      font-size: 1.2rem !important;
    }
    .ant-card-body {
      padding: 18px !important;
    }
    .ant-card-head {
      padding: 0 1rem;
    }
    .ant-card-meta {
      margin-bottom: 1rem;
    }
    .article-content {
      p {
        word-wrap: break-word;
        word-break: break-all;
        text-overflow: initial;
        white-space: normal;
        font-size: .9rem !important;
        margin-bottom: .8rem;
      }
    }
  }
</style>
